package in.iqing.control.helper;

import android.app.Activity;
import android.app.Fragment;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;

import in.iqing.app.R;


/**
 * Created by neavo on 14-3-7.
 */

public class IntentHelper {

	public static boolean isIntentAvailable(Context ctx, Intent intent) {
		return ctx.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
	}

	public static void startActivity(Activity source, Intent intent) {
		source.startActivityForResult(intent, 1);
		source.overridePendingTransition(R.anim.slide_in_from_right, R.anim.slide_out_from_left);
	}

	public static void startActivity(Activity source, Class<? extends Activity> target) {
		source.startActivityForResult(new Intent(source, target), 1);
		source.overridePendingTransition(R.anim.slide_in_from_right, R.anim.slide_out_from_left);
	}

	public static void startActivity(Activity source, Class<? extends Activity> target, Bundle extra) {
		source.startActivityForResult(new Intent(source, target).putExtras(extra), 1);
		source.overridePendingTransition(R.anim.slide_in_from_right, R.anim.slide_out_from_left);
	}

	public static void startActivityForResult(Activity source, Class<? extends Activity> target, Bundle extra, int requestCode) {
		source.startActivityForResult(new Intent(source, target).putExtras(extra), requestCode);
		source.overridePendingTransition(R.anim.slide_in_from_right, R.anim.slide_out_from_left);
	}

	public static void startActivityForResult(Activity source, Class<? extends Activity> target, int requestCode) {
		source.startActivityForResult(new Intent(source, target), requestCode);
		source.overridePendingTransition(R.anim.slide_in_from_right, R.anim.slide_out_from_left);
	}

	public static void startService(Context source, Intent intent) {
		source.startService(intent);
	}

	public static void startService(Context source, Class<? extends Service> target) {
		source.startService(new Intent(source, target));
	}

	public static void startService(Context source, Class<? extends Service> target, Bundle extra) {
		source.startService(new Intent(source, target).putExtras(extra));
	}
}
